const reverse = (x) => {
    let arr = [];
    let sum = 0;
    var num = String(Math.abs(x));
    if (x >= 0) {
        for (let i = 0; i < num.length; i++) {
            arr.push(num[i])
        };
        for (let j = 0; j < arr.length; j++) {
            sum += arr[j] * Math.pow(10, j)
        }
    } else {
        for (let i = 0; i < num.length; i++) {
            arr.push(num[i])
        };
        for (let j = 0; j < arr.length; j++) {
            sum += arr[j] * Math.pow(10, j)
        }
        sum = -sum
    }
    if (sum > (Math.pow(2, 31) - 1) || sum < Math.pow(-2, 31)) {
        sum = 0
    }
    return sum
}

console.log(reverse(-123));